﻿using FunnyArts.PrettyClient.Core.Logger;
using Microsoft.Extensions.Logging;

namespace FunnyArts.PrettyClient.Core.Utils
{
    public sealed class LoggerHelper
    {
        public static ILogger logger= null;
        private static readonly object lockObject = new object();

        public static ILogger Init(string logFilePath,string fileName)
        {
            logger=LoggerManager.Init(logFilePath, fileName);
            return logger;
        }

        public static void Debug(string message)
        {
            if (logger != null)
            {
                logger.LogDebug(message);
            }
        }

        public static async void DebugAsync(string message)
        {
            await Task.Run(() =>
            {
                lock (lockObject)
                {
                    if (logger == null) return;
                    logger.LogDebug(message);
                }
            });
        }

        public static void Info(string message)
        {
            if (logger != null)
            {
                logger.LogInformation(message);
            }
        }

        public static async void InfoAsync(string message)
        {
            await Task.Run(() =>
            {
                lock (lockObject)
                {
                    if (logger == null) return;
                    logger.LogInformation(message);
                }
            });
        }

        public static void Warning(string message)
        {
            if (logger != null)
            {
                logger.LogWarning(message);
            }
        }

        public static async void WarningAsync(string message)
        {
            await Task.Run(() =>
            {
                lock (lockObject)
                {
                    if (logger == null) return;
                    logger.LogWarning(message);
                }
            });
        }

        public static void Error(string message)
        {
            if (logger != null)
            {
                logger.LogError(message);
            }
        }

        public static async void ErrorAsync(string message)
        {
            await Task.Run(() =>
            {
                lock (lockObject)
                {
                    if (logger == null) return;
                    logger.LogError(message);
                }
            });
        }
    }
}
